home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / ironhors.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  253 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *ironhors_scroll;
  15. static int palettebank,charbank,spriterambank;
  16.  
  17.  
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23.   Iron Horse has three 256x4 palette PROMs (one per gun) and two 256x4
  24.   lookup table PROMs (one for characters, one for sprites).
  25.   I don't know for sure how the palette PROMs are connected to the RGB
  26.   output, but it's probably the usual:
  27.  
  28.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  29.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  30.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  31.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  32.  
  33. ***************************************************************************/
  34. void ironhors_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  35. {
  36.     int i;
  37.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  38.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  39.  
  40.  
  41.     for (i = 0;i < Machine->drv->total_colors;i++)
  42.     {
  43.         int bit0,bit1,bit2,bit3;
  44.  
  45.  
  46.         bit0 = (color_prom[0] >> 0) & 0x01;
  47.         bit1 = (color_prom[0] >> 1) & 0x01;
  48.         bit2 = (color_prom[0] >> 2) & 0x01;
  49.         bit3 = (color_prom[0] >> 3) & 0x01;
  50.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  51.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  52.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  53.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  54.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  55.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  56.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  57.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  58.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  59.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  60.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  61.  
  62.         color_prom++;
  63.     }
  64.  
  65.     color_prom += 2*Machine->drv->total_colors;
  66.     /* color_prom now points to the beginning of the character lookup table */
  67.  
  68.  
  69.     /* there are eight 32 colors palette banks; sprites use colors 0-15 and */
  70.     /* characters 16-31 of each bank. */
  71.     for (i = 0;i < TOTAL_COLORS(0)/8;i++)
  72.     {
  73.         int j;
  74.  
  75.  
  76.         for (j = 0;j < 8;j++)
  77.             COLOR(0,i + j * TOTAL_COLORS(0)/8) = (*color_prom & 0x0f) + 32 * j + 16;
  78.  
  79.         color_prom++;
  80.     }
  81.  
  82.     for (i = 0;i < TOTAL_COLORS(1)/8;i++)
  83.     {
  84.         int j;
  85.  
  86.  
  87.         for (j = 0;j < 8;j++)
  88.             COLOR(1,i + j * TOTAL_COLORS(1)/8) = (*color_prom & 0x0f) + 32 * j;
  89.  
  90.         color_prom++;
  91.     }
  92. }
  93.  
  94.  
  95.  
  96. WRITE_HANDLER( ironhors_charbank_w )
  97. {
  98.     if (charbank != (data & 1))
  99.     {
  100.         charbank = data & 1;
  101.         memset(dirtybuffer,1,videoram_size);
  102.     }
  103.  
  104.     spriterambank = data & 8;
  105.  
  106.     /* other bits unknown */
  107. }
  108.  
  109.  
  110.  
  111. WRITE_HANDLER( ironhors_palettebank_w )
  112. {
  113.     if (palettebank != (data & 7))
  114.     {
  115.         palettebank = data & 7;
  116.         memset(dirtybuffer,1,videoram_size);
  117.     }
  118. }
  119.  
  120.  
  121.  
  122. /***************************************************************************
  123.  
  124.   Draw the game screen in the given osd_bitmap.
  125.   Do NOT call osd_update_display() from this function, it will be called by
  126.   the main emulation engine.
  127.  
  128. ***************************************************************************/
  129. void ironhors_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  130. {
  131.     int offs,i;
  132.  
  133.  
  134.     /* for every character in the Video RAM, check if it has been modified */
  135.     /* since last time and update it accordingly. */
  136.     for (offs = videoram_size - 1;offs >= 0;offs--)
  137.     {
  138.         if (dirtybuffer[offs])
  139.         {
  140.             int sx,sy;
  141.  
  142.  
  143.             dirtybuffer[offs] = 0;
  144.  
  145.             sx = 8 * (offs % 32);
  146.             sy = 8 * (offs / 32);
  147.  
  148.             drawgfx(tmpbitmap,Machine->gfx[0],
  149.                     videoram[offs] + 16*(colorram[offs] & 0x20) + 4*(colorram[offs] & 0x40) + 1024 * charbank,
  150.                     (colorram[offs] & 0x0f) + 16 * palettebank,
  151.                     colorram[offs] & 0x10,colorram[offs] & 0x20,
  152.                     sx,sy,
  153.                     0,TRANSPARENCY_NONE,0);
  154.         }
  155.     }
  156.  
  157.  
  158.     /* copy the temporary bitmap to the screen */
  159.     {
  160.         int scroll[32];
  161.  
  162.  
  163.         for (i = 0;i < 32;i++)
  164.             scroll[i] = -(ironhors_scroll[i]);
  165.  
  166.         copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  167.     }
  168.  
  169.  
  170.     /* Draw the sprites. */
  171.     {
  172.         unsigned char *sr;
  173.  
  174.  
  175.         if (spriterambank != 0)
  176.             sr = spriteram;
  177.         else sr = spriteram_2;
  178.  
  179.         for (offs = 0;offs < spriteram_size;offs += 5)
  180.         {
  181.             if (sr[offs+2])
  182.             {
  183.                 int sx,sy,flipx,flipy,code,color;
  184.  
  185.  
  186.                 sx = sr[offs+3];
  187.                 sy = sr[offs+2];
  188.                 flipx = sr[offs+4] & 0x20;
  189.                 flipy = sr[offs+4] & 0x40;
  190.                 code = (sr[offs] << 2) + ((sr[offs+1] & 0x01) << 10) + ((sr[offs+1] & 0x0c) >> 2);
  191.                 color = ((sr[offs+1] & 0xf0)>>4) + 16 * palettebank;
  192.  
  193.                 switch (sr[offs+4] & 0x0c)
  194.                 {
  195.                     case 0x00:    /* 16x16 */
  196.                         drawgfx(bitmap,Machine->gfx[1],
  197.                                 code/4,
  198.                                 color,
  199.                                 flipx,flipy,
  200.                                 sx,sy,
  201.                                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  202.                         break;
  203.  
  204.                     case 0x04:    /* 16x8 */
  205.                         {
  206.                             drawgfx(bitmap,Machine->gfx[2],
  207.                                     code & ~1,
  208.                                     color,
  209.                                     flipx,flipy,
  210.                                     flipx?sx+8:sx,sy,
  211.                                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  212.                             drawgfx(bitmap,Machine->gfx[2],
  213.                                     code | 1,
  214.                                     color,
  215.                                     flipx,flipy,
  216.                                     flipx?sx:sx+8,sy,
  217.                                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  218.                         }
  219.                         break;
  220.  
  221.                     case 0x08:    /* 8x16 */
  222.                         {
  223.                             drawgfx(bitmap,Machine->gfx[2],
  224.                                     code & ~2,
  225.                                     color,
  226.                                     flipx,flipy,
  227.                                     sx,flipy?sy+8:sy,
  228.                                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  229.                             drawgfx(bitmap,Machine->gfx[2],
  230.                                     code | 2,
  231.                                     color,
  232.                                     flipx,flipy,
  233.                                     sx,flipy?sy:sy+8,
  234.                                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  235.                         }
  236.                         break;
  237.  
  238.                     case 0x0c:    /* 8x8 */
  239.                         {
  240.                             drawgfx(bitmap,Machine->gfx[2],
  241.                                     code,
  242.                                     color,
  243.                                     flipx,flipy,
  244.                                     sx,sy,
  245.                                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  246.                         }
  247.                         break;
  248.                 }
  249.             }
  250.         }
  251.     }
  252. }
  253.